window.onload=function(){
	alert("hello");
}

var dataRoot = document.getElementById("myBody").dataset.root;
var imgId = "";
var imgMsg= "";
var actid = document.getElementById("myBody").dataset.actid;
var userid = document.getElementById("myBody").dataset.userid;
var sub = document.getElementById("myBody").dataset.sub;
var homeurl = document.getElementById("myBody").dataset.homeurl;

 $(".bt .sub-btn").click(function(){
 //必须填写名字
        if ($("#name").val()== "") {
            alert("名字必填");
            $("#name").focus();
            return
        }
        //必须填写电话号码
        if ($("#phone").val()== "") {
            alert("号码必填");
            $("#phone").focus();
            return
        }

        if( $("#phone").val().length!=11 ){
            //$("#phone").val("");
            alert("手机号码不够11位");
            //$(this).attr("placeholder","请输入正确的手机号码！！！！！！");
            $("#phone").focus();
            return
        }
        var beginNum = $("#phone").val().substring(0,2);
        if( beginNum!=13 && beginNum!=15 && beginNum!=17 && beginNum!=18 ){
            //$("#phone").val("");
            alert("请输入正确的手机号码");
            $("#phone").focus();
            return
        }

        //必须上传至少一张图片
        if ($("#form1 img").attr('src') == "") {
            alert("至少上传一张图片！");
            return
        }
        //内容必填
        if ($(".messages textarea").val() == "") {
            alert("内容必填");
            $(".messages textarea").focus();
            return
        }
        for (var i = 1; i <= 8; i++) {
            imgid = "#form"+i+" img";
            var imgSrc = $(imgid).attr("id");
            if(imgSrc == undefined){
                break;
            }
            imgMsg += imgSrc+",";
        };
        imgMsg = imgMsg.substring(0,(imgMsg.length-1))
        var msg = {
            "name":$("#name").val(),
            "phone":$("#phone").val(),
            "picture_id":imgMsg,
            "introduce":$(".textarea-max").val(),
            "act_id":actid,
            "user_id":userid
        };
       
       $.ajax({
            url:sub,
            type:'get',
            data: msg ,
            success:function(res){
                //alert(res.request.status+' '+res.result.status);
                if(res.result.status == "success"){
                    alert("报名成功");
                    window.location.href = homeurl; 
                }else if(res.result.status == "fail"){
                    alert("报名失败");
                }
            }
        });
 })

  $(".textarea-max").keyup(function(){
        var hasnumber = $(this).val().length;
        let lastnumber = 60- hasnumber ;
        if($(this).val().length >= 60){
            $(this).next().html( "*不得超过60个字")
        }else{
            $(this).next().html( "*还剩下"+ lastnumber +"个字")
        }
    })